package chapter03
import org.apache.spark.{SparkConf, SparkContext}
object Test12_ClickNumber {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[*]").setAppName("Number")
    val sc = new SparkContext(conf)
    //读取文件
    val value = sc.textFile("input/apache.log")
    println(value.map(e=>e.split(" ")(3)
      .split(":")(0))
      .groupBy(e=>e)
      .map(e=>{(e._1,e._2.size)})
      .collect().mkString("Array(", ", ", ")"))
    //每个IP每天访问的次数
    println(value.map(e =>{
        val strings = e.split(" ")
        (strings(0),strings(3).split(":")(0))
      })
      .groupBy(e=>e)
      .map(e=>(e._1,e._2.size))
      .collect().mkString("Array(", ", ", ")"))
  }
}
